#include "Channel.h"
#include <stdlib.h>
//初始化一个Channel
struct Channel* channelInit(int fd, int events, handleFunc readFunc, handleFunc writeFunc, handleFunc destroyFunc, void* arg)
{
    struct Channel* channel = (struct Channel*)malloc(sizeof(struct Channel));
    channel->fd = fd;
    channel->events = events;
    channel->readCallBack = readFunc;
    channel->writeCallBack = writeFunc;
    channel->destroyCallBack = destroyFunc;
    channel->arg = arg;
    return channel;
}

//修改fd的写事件(检测or不检测)
void writeEventEnable(struct Channel* channel, bool flag)
{
    if(flag)
    {
        channel->events |= WriteEvent;//添加写标志位
    }
    else
    {
        channel->events = channel->events & ~WriteEvent;//清除写标志位，改为0
    }
}

//判断是否需要检测文件描述符的写事件
bool isWriteEventEnable(struct Channel* channel)
{
    return channel->events & WriteEvent;
}